package priv.hehe.service;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import priv.hehe.util.JdbcUtil;
import priv.hehe.util.JdbcUtil.JdbcVisitor;

public class GjpZhangwuService {

	public List<Map<String, Object>> selectAll() throws Exception{
		String sql = "select * from gjp_zhangwu";
		//获取结果集的容器
		List<Map<String, Object>> list=new ArrayList<Map<String,Object>>();
		JdbcUtil.queryAll(sql, new JdbcVisitor() {
			@Override
			public Object handlerResult(ResultSet resultSet) {
				try {
					//获取结果集的元信息
					ResultSetMetaData metaData = resultSet.getMetaData();
					Map<String, Object> map=new HashMap<String, Object>(); 
					for (int i = 1; i <= metaData.getColumnCount(); i++) {//迭代每一行的每一列
						String columnLabel = metaData.getColumnLabel(i);//将单元格的数据装入结果中
						map.put(columnLabel, resultSet.getObject(columnLabel));
					}
					list.add(map);
				} catch (SQLException e) {
					e.printStackTrace();
				}
				return null;
			}
		});
		return list;
	}
}
